#include <TransformComponent.h>
#include <ALEstd.h>

#pragma warning( disable : 4244)

const char* TransformComponent2D::g_name = "TransformComponent2D";
const ComponentId& TransformComponent2D::g_ID = ActorComponent::GetIdFromName(TransformComponent2D::g_name);

bool TransformComponent2D::VInit(tinyxml2::XMLElement* pData)
{
	tinyxml2::XMLElement* pPositionElement = pData->FirstChildElement("Position");
	if (pPositionElement)
	{
		double x = 0;
		double y = 0;
		pPositionElement->QueryDoubleAttribute("x", &x);
		pPositionElement->QueryDoubleAttribute("y", &y);

		m_position = Vec2(x, y);
	}

	tinyxml2::XMLElement* pOrientationElement = pData->FirstChildElement("Orientation");
	if (pOrientationElement)
	{
		pOrientationElement->QueryDoubleAttribute("angle", &m_orientation); 
	}

	tinyxml2::XMLElement* pSizeElement = pData->FirstChildElement("Size");
	if (pSizeElement)
	{
		double width = 0;
		double height = 0;
		pSizeElement->QueryDoubleAttribute("width", &width); 
		pSizeElement->QueryDoubleAttribute("height", &height); 

		m_size = Vec2(width, height);
	}

	return true;
}

#pragma warning( default : 4244)

ActorComponent* CreateTransformComponent2D()
{
	return ALE_NEW TransformComponent2D();
}